#include "StdAfx.h"
#include "I2C_LM75.h"

I2C_LM75::I2C_LM75(ComPorts* com, unsigned char Adresse, float korrektur	)
{
	C1 = com;
	Adress = Adresse;
	Korrektur = korrektur;
}

I2C_LM75::~I2C_LM75(void)
{
}

float I2C_LM75::read_temperature(void)
{
	unsigned char Tmpl;
	signed char Tmph;
	float ret;

	C1 -> I2C_start();
	C1 -> I2C_tx_byte(Adress);
	// Check for acknowledge from I2C device
	if (!C1 -> I2C_read_ack())	
	{
		C1 -> I2C_stop();
		return -1000;
	}
	Tmph = (signed char)(C1 -> I2C_rx_byte());
	C1 -> I2C_send_ack();	
	Tmpl = C1 -> I2C_rx_byte();
	C1 -> I2C_send_nack();
	C1 -> I2C_stop();

	ret = (float)Tmph + (Tmpl >> 7)*0.5f;

	return ret + Korrektur;	
}
